﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Kiosk.Library;
using System.Windows.Media.Animation;


namespace Kiosk.UserControls
{
    /// <summary>
    /// Interaction logic for NotificationListPresenter.xaml
    /// </summary>
    public partial class NotificationListPresenter : UserControl
    {
        public string Title
        {
            get
            {
                return txtHeading.Text;
            }
            set
            {
                txtHeading.Text = value;
            }
        }

        int _maxNumDisplayed = 4;
        public int MaxNumberItemsDisplayed
        {
            get
            {
                return _maxNumDisplayed;
            }
            set
            {
                _maxNumDisplayed = value;
                lstNotifications.MaxHeight = (_maxNumDisplayed * 45) + 5;
                
            }
        }

        public event NotificationSelectEventHandler NotificationSelected;


        public NotificationListPresenter()
        {
            InitializeComponent();
            
        }

        private void lstNotifications_SelectionChanged(object sender, MouseEventArgs e)
        {
            if (lstNotifications.SelectedIndex != -1)
            {
                Kiosk.Library.NotificationInfo n = (Kiosk.Library.NotificationInfo)lstNotifications.SelectedItem;
                NotificationSelected(this, new NotificationSelectEventArgs(n));
            }
        }

        public void ClearSelection()
        {
            lstNotifications.SelectedIndex = -1;
        }

        private void lstNotifications_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (lstNotifications.Items.Count == 0)
            {
                this.Visibility = Visibility.Collapsed;
            }
            else
            {
                foreach (object note in lstNotifications.Items)
                {
                    if (note is Notification)
                    {
                        Notification n = (Notification)note;
                    }
                }
                this.Visibility = Visibility.Visible;
            }
        }

        private void lstNotifications_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            
        }

        private void uc_dataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {

        }

    }

    public delegate void NotificationSelectEventHandler(object sender, NotificationSelectEventArgs e);

    public class NotificationSelectEventArgs : EventArgs
    {
        public NotificationInfo Notification { get; set; }
        public NotificationSelectEventArgs(NotificationInfo not)
        {
            this.Notification = not;
        }

    }

}
